<?php
/**
 * ----------------------------------------------------------------------------
 * 行到水穷处，坐看云起时
 * 开发软件，找贵阳云起信息科技，官网地址:https://www.56q7.com/
 * ----------------------------------------------------------------------------
 * Author: 老成
 * email：85556713@qq.com
 */
declare (strict_types = 1);

namespace app\admin\controller\cmstool;

use app\common\controller\Backend;
use app\common\library\Http;
use think\annotation\route\Group;
use think\annotation\route\Route;
use think\facade\Cache;

#[Group("cmstool/plagiarism")]
class Plagiarism extends Backend
{
    #[Route('GET,POST','index')]
    public function index()
    {
        if($this->request->isPost()){
            $plagdata=$this->request->post("row/a");
            Cache::set("plagiarism",$plagdata);
            $this->success('开始启动');
        }
        return $this->fetch();
    }

    #[Route('GET','run')]
    public function run()
    {
        ini_set('max_execution_time','500');
        $data=Cache::get("plagiarism");
        if(!$data){
           $this->error('请先配置仿站参数!');
        }
        $service=new \app\admin\service\cmstool\Plagiarism();
        $service->make($data['url'],$data['tempfile'],$data['imgcode']);
        if(isset($data['cookies']) && $data['cookies']){
            $service->setCookie($data['cookies']);
        }
        header('Content-Type: text/html');
        header('Cache-Control: no-cache');
        header('X-Accel-Buffering: no');
        while($service->progress()){}
        Cache::delete('plagiarism');
        exit;
    }
}